package org.caijuan.transaction.sqlexception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

@RestController
@RequestMapping("/sqlexception")
@Slf4j
public class SQLExceptionController {

    @Autowired
    private SQLExceptionService sqlExceptionService;

    @GetMapping("wrong")
    public int wrong(@RequestParam("name") String name) throws SQLException {
        sqlExceptionService.createUserWrong(name);
        return sqlExceptionService.getUserCount(name);
    }

    @GetMapping("right")
    public int right(@RequestParam("name") String name) {
        sqlExceptionService.createUserRight(name);
        return sqlExceptionService.getUserCount(name);
    }
}
